home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 1 / Cream of the Crop 1.iso / PROGRAM / CBGRX100.ARJ / MEMFILL.H < prev    next >
Text File  |  1992-04-10  |  9KB  |  271 lines

  1. /** 
  2.  ** MEMFILL.H 
  3.  **
  4.  **  Copyright (C) 1992, Csaba Biegl
  5.  **    820 Stirrup Dr, Nashville, TN, 37221
  6.  **    csaba@vuse.vanderbilt.edu
  7.  **
  8.  **  This file is distributed under the terms listed in the document
  9.  **  "copying.cb", available from the author at the address above.
  10.  **  A copy of "copying.cb" should accompany this file; if not, a copy
  11.  **  should be available from where this file was obtained.  This file
  12.  **  may not be distributed without a verbatim copy of "copying.cb".
  13.  **  You should also have received a copy of the GNU General Public
  14.  **  License along with this program (it is in the file "copying");
  15.  **  if not, write to the Free Software Foundation, Inc., 675 Mass Ave,
  16.  **  Cambridge, MA 02139, USA.
  17.  **
  18.  **  This program is distributed in the hope that it will be useful,
  19.  **  but WITHOUT ANY WARRANTY; without even the implied warranty of
  20.  **  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  21.  **  GNU General Public License for more details.
  22.  **/
  23.  
  24. #ifndef _MEMFILL_H_
  25. #define _MEMFILL_H_
  26.  
  27. #ifdef  __TURBOC__
  28. #pragma inline
  29. #endif
  30.  
  31. /*
  32.  * utilities -- other files may define them too
  33.  */
  34. #ifndef _SaveDS
  35.  
  36. #ifdef  __TURBOC__
  37. #define _ClrDir()    asm cld
  38. #define _SetDir()    asm std
  39. #define _SaveDS()    asm push    ds
  40. #define _RestoreDS()    asm pop        ds
  41. #endif
  42.  
  43. #ifdef  __GNUC__
  44. #define _ASV        asm volatile
  45. #define _ClrDir()    _ASV("cld")
  46. #define _SetDir()    _ASV("std")
  47. #define _SaveDS()
  48. #define _RestoreDS()
  49. #endif
  50.  
  51. #endif  /* _SaveDS */
  52.  
  53. /*
  54.  * set a pixel row
  55.  */
  56. #ifdef  __TURBOC__
  57. #define _MF_ROWSET_(addr,data,len,SZ) do {                    \
  58.     _CX = len;                                \
  59.     _AX = data;                                \
  60.     asm les        di,DWORD PTR addr;                        \
  61.     asm rep        stos##SZ;                            \
  62. } while(0)
  63. #endif
  64.  
  65. #ifdef  __GNUC__
  66. #define _MF_ROWSET_(addr,data,len,SZ) _ASV(                 "\n\
  67.     movl    %0,%%edi                          \n\
  68.     movl    %1,%%eax                          \n\
  69.     movl    %2,%%ecx                          \n\
  70.     rep                                  \n\
  71.     stos"#SZ"                               "\
  72.     : /* NOTHING */                                \
  73.     : "g" (addr), "g" (data), "g" (len)                    \
  74.     : "di", "cx", "ax"                            \
  75. )
  76. #endif
  77.  
  78. #define _RowSetB(ID,addr,data,len)    _MF_ROWSET_(addr,data,len,b)
  79. #define _RowSetW(ID,addr,data,len)    _MF_ROWSET_(addr,data,len,w)
  80. #define _RowSetL(ID,addr,data,len)    _MF_ROWSET_(addr,data,len,l)
  81.  
  82. /*
  83.  * set a pixel row with logical operations
  84.  */
  85. #ifdef  __TURBOC__
  86. #define _MF_ROWSETOPR_(addr,data,len,OPR,REG,SZ,ID) do {            \
  87.     _CX = len;                                \
  88.     _DX = data;                                \
  89.     asm les        di,DWORD PTR addr;                        \
  90. MF_RowSet##ID##Loop:                                \
  91.     asm mov        ax,dx;                            \
  92.     asm OPR        REG,es:[di];                        \
  93.     asm stos##SZ;                                \
  94.     asm loop    MF_RowSet##ID##Loop;                    \
  95. } while(0)
  96. #endif
  97.  
  98. #ifdef  __GNUC__
  99. #define _MF_ROWSETOPR_(addr,data,len,OPR,REG,SZ,ID) _ASV(         "\n\
  100.     movl    %0,%%edi                          \n\
  101.     movl    %1,%%edx                          \n\
  102.     movl    %2,%%ecx                          \n\
  103. L_MF_RowSet"#ID"Loop:                              \n\
  104.     movl    %%edx,%%eax                          \n\
  105.     "#OPR #SZ"  (%%edi),%%"#REG"                      \n\
  106.     stos"#SZ"                              \n\
  107.     loop    L_MF_RowSet"#ID"Loop                       "\
  108.     : /* NOTHING */                                \
  109.     : "g" (addr), "g" (data), "g" (len)                    \
  110.     : "di", "dx", "cx", "ax"                        \
  111. )
  112. #endif
  113.  
  114. #define _RowSetXorB(ID,addr,data,len)    _MF_ROWSETOPR_(addr,data,len,xor,al,b,ID##XB)
  115. #define _RowSetOrB(ID,addr,data,len)    _MF_ROWSETOPR_(addr,data,len,or,al,b,ID##OB)
  116. #define _RowSetAndB(ID,addr,data,len)    _MF_ROWSETOPR_(addr,data,len,and,al,b,ID##AB)
  117.  
  118. #define _RowSetXorW(ID,addr,data,len)    _MF_ROWSETOPR_(addr,data,len,xor,ax,w,ID##XW)
  119. #define _RowSetOrW(ID,addr,data,len)    _MF_ROWSETOPR_(addr,data,len,or,ax,w,ID##OW)
  120. #define _RowSetAndW(ID,addr,data,len)    _MF_ROWSETOPR_(addr,data,len,and,ax,w,ID##AW)
  121.  
  122. #define _RowSetXorL(ID,addr,data,len)    _MF_ROWSETOPR_(addr,data,len,xor,eax,l,ID##XL)
  123. #define _RowSetOrL(ID,addr,data,len)    _MF_ROWSETOPR_(addr,data,len,or,eax,l,ID##OL)
  124. #define _RowSetAndL(ID,addr,data,len)    _MF_ROWSETOPR_(addr,data,len,and,eax,l,ID##AL)
  125.  
  126. /*
  127.  * set a pixel column with logical operations
  128.  */
  129. #ifdef  __TURBOC__
  130. #define _MF_COLSETOPR_(addr,offs,data,hgt,OPR,REG,SZ,ID) do {            \
  131.     _DX = offs;                                \
  132.     _CX = hgt;                                \
  133.     _AX = data;                                \
  134.     asm les        di,DWORD PTR addr;                        \
  135. MF_ColSet##ID##Loop:                                \
  136.     asm OPR        es:[di],REG;                        \
  137.     asm add        di,dx;                            \
  138.     asm loop    MF_ColSet##ID##Loop;                    \
  139. } while(0)
  140. #endif
  141.  
  142. #ifdef  __GNUC__
  143. #define _MF_COLSETOPR_(addr,offs,data,hgt,OPR,REG,SZ,ID) _ASV(         "\n\
  144.     movl    %0,%%edi                          \n\
  145.     movl    %1,%%edx                          \n\
  146.     movl    %2,%%eax                          \n\
  147.     movl    %3,%%ecx                          \n\
  148. L_MF_ColSet"#ID"Loop:                              \n\
  149.     "#OPR #SZ"  %%"#REG",(%%edi)                      \n\
  150.     addl    %%edx,%%edi                          \n\
  151.     loop    L_MF_ColSet"#ID"Loop                       "\
  152.     : /* NOTHING */                                \
  153.     : "g" (addr), "g" (offs), "g" (data), "g" (hgt)                \
  154.     : "di", "dx", "cx", "ax"                        \
  155. )
  156. #endif
  157.  
  158. #define _ColSetB(ID,adr,ofs,dta,h)    _MF_COLSETOPR_(adr,ofs,dta,h,mov,al,b,ID##B)
  159. #define _ColSetXorB(ID,adr,ofs,dta,h)    _MF_COLSETOPR_(adr,ofs,dta,h,xor,al,b,ID##XB)
  160. #define _ColSetOrB(ID,adr,ofs,dta,h)    _MF_COLSETOPR_(adr,ofs,dta,h,or,al,b,ID##OB)
  161. #define _ColSetAndB(ID,adr,ofs,dta,h)    _MF_COLSETOPR_(adr,ofs,dta,h,and,al,b,ID##AB)
  162.  
  163. #define _ColSetW(ID,adr,ofs,dta,h)    _MF_COLSETOPR_(adr,ofs,dta,h,mov,ax,w,ID##W)
  164. #define _ColSetXorW(ID,adr,ofs,dta,h)    _MF_COLSETOPR_(adr,ofs,dta,h,xor,ax,w,ID##XW)
  165. #define _ColSetOrW(ID,adr,ofs,dta,h)    _MF_COLSETOPR_(adr,ofs,dta,h,or,ax,w,ID##OW)
  166. #define _ColSetAndW(ID,adr,ofs,dta,h)    _MF_COLSETOPR_(adr,ofs,dta,h,and,ax,w,ID##AW)
  167.  
  168. #define _ColSetL(ID,adr,ofs,dta,h)    _MF_COLSETOPR_(adr,ofs,dta,h,mov,eax,l,ID##L)
  169. #define _ColSetXorL(ID,adr,ofs,dta,h)    _MF_COLSETOPR_(adr,ofs,dta,h,xor,eax,l,ID##XL)
  170. #define _ColSetOrL(ID,adr,ofs,dta,h)    _MF_COLSETOPR_(adr,ofs,dta,h,or,eax,l,ID##OL)
  171. #define _ColSetAndL(ID,adr,ofs,dta,h)    _MF_COLSETOPR_(adr,ofs,dta,h,and,eax,l,ID##AL)
  172.  
  173. /*
  174.  * set a pixel block
  175.  */
  176. #ifdef  __TURBOC__
  177. #define _MF_BLKSET_(addr,offs,data,wdt,hgt,SZ,ID) do {                \
  178.     _DX = offs;                                \
  179.     _BX = hgt;                                \
  180.     _AX = data;                                \
  181.     asm les        di,DWORD PTR addr;                        \
  182. MF_BlkSet##ID##Loop:                                \
  183.     asm mov        cx,WORD  PTR wdt;                        \
  184.     asm rep        stos##SZ;                            \
  185.     asm add        di,dx;                            \
  186.     asm dec        bx;                                \
  187.     asm jnz        MF_BlkSet##ID##Loop;                    \
  188. } while(0)
  189. #endif
  190.  
  191. #ifdef  __GNUC__
  192. #define _MF_BLKSET_(addr,offs,data,wdt,hgt,SZ,ID) _ASV(             "\n\
  193.     movl    %0,%%edi                          \n\
  194.     movl    %1,%%edx                          \n\
  195.     movl    %2,%%eax                          \n\
  196.     movl    %4,%%ebx                          \n\
  197. L_MF_BlkSet"#ID"Loop:                              \n\
  198.     movl    %3,%%ecx                          \n\
  199.     rep                                  \n\
  200.     stos"#SZ"                              \n\
  201.     addl    %%edx,%%edi                          \n\
  202.     decl    %%ebx                              \n\
  203.     jnz    L_MF_BlkSet"#ID"Loop                       "\
  204.     : /* NOTHING */                                \
  205.     : "g" (addr), "g" (offs), "g" (data), "g" (wdt), "g" (hgt)        \
  206.     : "di", "dx", "cx", "bx", "ax"                        \
  207. )
  208. #endif
  209.  
  210. #define _BlkSetB(ID,adr,ofs,dta,wd,hg)  _MF_BLKSET_(adr,ofs,dta,wd,hg,b,ID##B)
  211. #define _BlkSetW(ID,adr,ofs,dta,wd,hg)  _MF_BLKSET_(adr,ofs,dta,wd,hg,w,ID##W)
  212. #define _BlkSetL(ID,adr,ofs,dta,wd,hg)  _MF_BLKSET_(adr,ofs,dta,wd,hg,l,ID##L)
  213.  
  214. /*
  215.  * set a pixel block with logical operations
  216.  */
  217. #ifdef  __TURBOC__
  218. #define _MF_BLKSETOPR_(addr,offs,data,wdt,hgt,OPR,REG,SZ,ID) do {        \
  219.     _SI = offs;                                \
  220.     _BX = hgt;                                \
  221.     _DX = data;                                \
  222.     asm les        di,DWORD PTR addr;                        \
  223. MF_BlkSet##ID##VertLoop:                            \
  224.     asm mov        cx,WORD  PTR wdt;                        \
  225. MF_BlkSet##ID##LineLoop:                            \
  226.     asm mov        ax,dx;                            \
  227.     asm OPR        REG,es:[di];                        \
  228.     asm stos##SZ;                                \
  229.     asm loop    MF_BlkSet##ID##LineLoop;                    \
  230.     asm add        di,si;                            \
  231.     asm dec        bx;                                \
  232.     asm jnz        MF_BlkSet##ID##VertLoop;                    \
  233. } while(0)
  234. #endif
  235.  
  236. #ifdef  __GNUC__
  237. #define _MF_BLKSETOPR_(addr,offs,data,wdt,hgt,OPR,REG,SZ,ID) _ASV(     "\n\
  238.     movl    %0,%%edi                          \n\
  239.     movl    %2,%%edx                          \n\
  240.     movl    %4,%%ebx                          \n\
  241. L_MF_BlkSet"#ID"VertLoop:                          \n\
  242.     movl    %3,%%ecx                          \n\
  243. L_MF_BlkSet"#ID"LineLoop:                          \n\
  244.     movl    %%edx,%%eax                          \n\
  245.     "#OPR #SZ"  (%%edi),%%"#REG"                      \n\
  246.     stos"#SZ"                              \n\
  247.     loop    L_MF_BlkSet"#ID"LineLoop                  \n\
  248.     addl    %1,%%edi                          \n\
  249.     decl    %%ebx                              \n\
  250.     jne    L_MF_BlkSet"#ID"VertLoop                   "\
  251.     : /* NOTHING */                                \
  252.     : "g" (addr), "g" (offs), "g" (data), "g" (wdt), "g" (hgt)        \
  253.     : "di", "dx", "cx", "bx", "ax"                        \
  254. )
  255. #endif
  256.  
  257. #define _BlkSetXorB(ID,adr,ofs,dta,w,h) _MF_BLKSETOPR_(adr,ofs,dta,w,h,xor,al,b,ID##XB)
  258. #define _BlkSetOrB(ID,adr,ofs,dta,w,h)  _MF_BLKSETOPR_(adr,ofs,dta,w,h,or,al,b,ID##OB)
  259. #define _BlkSetAndB(ID,adr,ofs,dta,w,h) _MF_BLKSETOPR_(adr,ofs,dta,w,h,and,al,b,ID##AB)
  260.  
  261. #define _BlkSetXorW(ID,adr,ofs,dta,w,h) _MF_BLKSETOPR_(adr,ofs,dta,w,h,xor,ax,w,ID##XW)
  262. #define _BlkSetOrW(ID,adr,ofs,dta,w,h)  _MF_BLKSETOPR_(adr,ofs,dta,w,h,or,ax,w,ID##OW)
  263. #define _BlkSetAndW(ID,adr,ofs,dta,w,h) _MF_BLKSETOPR_(adr,ofs,dta,w,h,and,ax,w,ID##AW)
  264.  
  265. #define _BlkSetXorL(ID,adr,ofs,dta,w,h) _MF_BLKSETOPR_(adr,ofs,dta,w,h,xor,eax,l,ID##XL)
  266. #define _BlkSetOrL(ID,adr,ofs,dta,w,h)  _MF_BLKSETOPR_(adr,ofs,dta,w,h,or,eax,l,ID##OL)
  267. #define _BlkSetAndL(ID,adr,ofs,dta,w,h) _MF_BLKSETOPR_(adr,ofs,dta,w,h,and,eax,l,ID##AL)
  268.  
  269. #endif  /* whole file */
  270.  
  271.